package Controllers;

import DAO.Reservation_Dao;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;

public class Reservation_Validator {

    public Reservation_Validator(Reservation_Dao reservation_Dao) {

    }

    public Reservation_Validator() {

    }

    public boolean validateReservation(String Name, String LastName, String PhoneNumber, String SeatsNumber, String dateString) {
        boolean reservationTyped = true;
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        String dtStr = dateString.trim();
        Date date = null;
        try {
            date = df.parse(dtStr);
        } catch (ParseException e) {
            JOptionPane.showMessageDialog(null, "Incorrect date format");
        }
        if (Calendar.getInstance().getTime().after(date)) {
            JOptionPane.showMessageDialog(null, "Date has already passed");
        }
        if (Name.isEmpty() || LastName.isEmpty() || PhoneNumber.isEmpty() || SeatsNumber.isEmpty()) {
            reservationTyped = false;
        } else if (PhoneNumber.matches("[0-9]+") == false) {
            reservationTyped = false;
        } else if (PhoneNumber.length() > 10 || PhoneNumber.length() < 10) {
            reservationTyped = false;
        } else if (SeatsNumber.matches("[0-9]+") == false) {
            reservationTyped = false;
        } else if (Integer.parseInt(SeatsNumber) > 10) {
            reservationTyped = false;
        }
        return reservationTyped;
    }
}
